<?php

if (! function_exists('array_get')) {
    /**
     * Get an item from an array using "dot" notation.
     *
     * @param  \ArrayAccess|array  $array
     * @param  string|int|null  $key
     * @param  mixed  $default
     * @return mixed
     */
    function array_get($array,$key,$default=null){
        return \Illuminate\Support\Arr::get($array,$key,$default);
    }
}


if (! function_exists('template')) {
    /**
     * Get the evaluated view contents for the given view.
     *
     * @param  string|null  $view
     * @param  \Illuminate\Contracts\Support\Arrayable|array  $data
     * @param  array  $mergeData
     * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory
     */
    function template($view = null, $data = [], $mergeData = []){
        $device = is_mobile()?"mobile":"web";
        return view($device.'.'.$view,$data,$mergeData);
    }
}


if (! function_exists('is_mobile')) {
    /**
     * 判断是否为手机端
     *
     * @return bool
     */
    function is_mobile()
    {

        // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
        if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
        {
            return true;
        }
        // 脑残法，判断手机发送的客户端标志,兼容性有待提高
        if (isset ($_SERVER['HTTP_USER_AGENT']))
        {
            $clientkeywords = array (
                'iphone',
                'android',
                'mobile',
                'ipad'
            );
            // 从HTTP_USER_AGENT中查找手机浏览器的关键字
            if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
            {
                return true;
            }
        }
        return false;
    }
}

if (! function_exists('setting_get')) {
    /**
     * 获取设置
     *
     * @param string $name
     * @return bool
     */
    function setting_get($name)
    {
        return \App\Support\Setting::get($name);
    }
}